package org.bob.web.controller;

import lombok.extern.slf4j.Slf4j;
import org.bob.service.SuggestService;
import org.bob.web.model.SuggestReq;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

import java.util.List;

/**
 * 搜索建议控制类
 */
@Slf4j
@CrossOrigin
@RestController
public class SuggestController extends BaseController {

    private final SuggestService suggestService;

    public SuggestController(SuggestService suggestService) {
        this.suggestService = suggestService;
    }

    /**
     * 搜索内容方法
     * @return
     */
    @PostMapping("/suggest")
    public Mono<List<String>> suggest(@RequestBody @Validated SuggestReq req){
        return Mono.just(suggestService.search(req));
    }
}
